package ink.lovejinhu.leetcode;

import ink.lovejinhu.common.Node;

import java.util.ArrayList;
import java.util.List;

public class Solution_0589 {
    /**
     * N叉树的前序遍历
     *
     * @param root
     * @return
     */
    public List<Integer> preorder(Node root) {
        this.dfs(root);
        return list;
    }

    public List<Integer> list = new ArrayList<>();

    public void dfs(Node root) {
        if (root == null) {
            return;
        }
        list.add(root.val);
        if (root.children == null) {
            return;
        }
        for (int i = 0; i < root.children.size(); i++) {
            dfs(root.children.get(i));
        }
    }
}
